package com.ict.web.controller.yzq;
;
import com.ict.common.annotation.Log;
import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.core.page.TableDataInfo;
import com.ict.common.enums.BusinessType;
import com.ict.web.dto.InsertNoticeDto;
import com.ict.web.dto.QueryNoticeDto;
import com.ict.web.dto.UpdateNoticeDto;
import com.ict.web.service.INoticeService;
import com.ict.web.vo.NoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 公告Controller
 * @author xss
 * @date 2022-02-15
 */
@Api(tags = "公告接口")
@RestController
@RequestMapping("/web/notice")
public class NoticeController extends BaseController
{
    @Autowired
    private INoticeService noticeService;

    /**
     * 查询公告列表
     * @param queryDto
     * @return
     */
    @ApiOperation("查询公告列表")
    @GetMapping("/list")
    public TableDataInfo noticeList(QueryNoticeDto queryDto){
        startPage();
        List<NoticeVo> list = noticeService.selectNoticeList(queryDto);
        return getDataTable(list);
    }

    /**
     * 查询公告详情
     * @param noticeId
     * @return
     */
    @ApiOperation("查询公告详情")
    @GetMapping("/{noticeId}")
    public AjaxResult getNoticeDetail(@PathVariable("noticeId") Long noticeId){

        return AjaxResult.success(noticeService.selectNoticeByNoticeId(noticeId));
    }

    /**
     * 发布公告信息
     * @param addDto
     * @return
     */
    @ApiOperation("发布公告")
    @PostMapping("/releaseNotice")
    @Log(title = "公告",businessType = BusinessType.INSERT)
    public AjaxResult releaseNotice(@RequestBody InsertNoticeDto addDto){

        return toAjax(noticeService.releaseNotice(addDto));
    }
    /**
     * 保存公告信息
     * @param addDto
     * @return
     */
    @ApiOperation("保存公告")
    @PostMapping("/saveNotice")
    @Log(title = "公告",businessType = BusinessType.INSERT)
    public AjaxResult saveNotice(@RequestBody InsertNoticeDto addDto){

        return toAjax(noticeService.saveNotice(addDto));
    }

    /**
     * 修改保存公告信息
     * @param updateDto
     * @return
     */
    @ApiOperation("修改保存公告信息")
    @PutMapping("/editSaveNotice")
    @Log(title = "公告",businessType = BusinessType.UPDATE)
    public AjaxResult editSave(@RequestBody UpdateNoticeDto updateDto){

        return toAjax(noticeService.updateSaveNotice(updateDto));
    }

    /**
     * 更新公告信息
     * @param updateDto
     * @return
     */
    @ApiOperation("修改发布公告信息")
    @PutMapping("/editReleaseNotice")
    @Log(title = "公告",businessType = BusinessType.UPDATE)
    public AjaxResult editRelease(@RequestBody UpdateNoticeDto updateDto){

        return toAjax(noticeService.updateReleaseNotice(updateDto));
    }

    @ApiOperation("删除公告")
    @DeleteMapping("/remove/{noticeId}")
    @Log(title = "公告",businessType = BusinessType.DELETE)
    public AjaxResult deleteNotice(@PathVariable("noticeId")Long noticeId){

        return toAjax(noticeService.deleteNoticeByNoticeId(noticeId));
    }

}
